<?php

/******************************************
 * File:			lib_safe.php
 * Version:			1.0.1
 * Last modified:	25/10/2009
 * Last modifier:	Hugo Lavigne
 *****************************************/

Function is_actif_mod($mod)
{
	$table_modules = $_SESSION['prefix']."modules";
	$req = dbquery("SELECT mid FROM $table_modules WHERE path='$mod' AND actif='ok'");
	if (@mysql_num_rows($req) > 0)
		return(TRUE);
	return(FALSE);
}

Function check()
{
	if (!is_actif_mod($_SESSION['page']))
	{
		redirect("login.php?err=4", 1);
		exit;
	}
	
	$uids_ok = get_ids_ok($_SESSION['page'], "uid");
	$gids_ok = get_ids_ok($_SESSION['page'], "gid");
	
	$flag = "ko";
	
	if ($uids_ok != -1)
	{
		$nb = count($uids_ok);
		$i = 0;
		while ($i < $nb)
		{
			if ($uids_ok[$i] == $_SESSION['uid'])
			{
				$flag = "ok";
				break;
			}
			$i++;
		}
	}
	
	if ($flag == "ko")
	{
		if ($gids_ok != -1)
		{
			$nb = count($gids_ok);
			$i = 0;
			while ($i < $nb)
			{
				if (is_in_group($gids_ok[$i], @$_SESSION['uid']))
				{
					$flag = "ok";
					break;
				}
				$i++;
			}
		}
	}
	
	if (!is_administrator(@$_SESSION['uid']))
	{
		if (($uids_ok != -1) || ($gids_ok != -1))
		{
			if ($flag == "ko")
			{
				redirect("login.php?err=4", 1);
				exit;
			}
		}
	}
	return (0);
}

?>